package Huihu.src.Test;
/*
特点：无序和唯一性
 */

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

public class dome11 {
    public static void main(String[] args) {
        //创建集合
        Set<Student> set=new HashSet<>();
        //创建元素对象
        Student student1=new Student("张三",12);
        Student student2=new Student("王五",13);
        Student student3=new Student("李四",14);
        Student student4=new Student("牛五",15);
        //将元素对象添加进集合中
        set.add(student1);
        set.add(student2);
        set.add(student3);
        set.add(student4);
        //遍历集合
        System.out.println(set);

        System.out.println("----------");

        //通过迭代器遍历set集合
        Iterator<Student> it=set.iterator();
        while (it.hasNext()){
            Student s=it.next();
            System.out.println(s);
        }

        System.out.println("----------");

        //通过增强for循环遍历set集合
        for (Student student : set) {
            System.out.println(student);
        }
    }
}
